<template>
	<view>
		<slot></slot>
		<gui-modal ref="popup" v-if="$store.state.base.dx_config" :customClass="['gui-bg-white', 'gui-dark-bg-level-3', 'gui-border-radius']"
			title="注销验证码">
			<template v-slot:content>
				<view class="gui-flex gui-space-between gui-align-items-center gui-padding-x">
					<view class="gui-margin gui-bg-gray gui-border-radius" style="padding: 16rpx 20rpx;">
						<input v-model="code" type="number" placeholder="请输入验证码" />
					</view>
					<view v-if="time==0" class="gui-bg-blue gui-color-white gui-text gui-flex-shrink0"
						style="padding: 20rpx 20rpx;">重新发送</view>
					<view v-else class="gui-bg-gray gui-color-black gui-text gui-flex-shrink0"
						style="padding: 20rpx 20rpx;">{{time}}s</view>
				</view>

			</template>

			<!-- 利用 flex 布局 可以放置多个自定义按钮哦  -->
			<template v-slot:btns>
				<view class="gui-padding">
					<button type="default" @tap="comfirm" class="gui-button-mini  gui-bg-blue gui-color-white">
						确认
					</button>
				</view>
			</template>
		</gui-modal>
			<gui-modal ref="popup" v-else :customClass="['gui-bg-white', 'gui-dark-bg-level-3', 'gui-border-radius']"
			title="请在下方输入框里输入“确认注销”">
			<template v-slot:content>
				<view class="gui-flex gui-space-between gui-align-items-center gui-padding-x">
					<view class="gui-margin gui-bg-gray gui-border-radius" style="padding: 16rpx 20rpx;">
						<input v-model="code"  placeholder="请输入（确认注销）确认" />
					</view>
					
				</view>

			</template>

			<!-- 利用 flex 布局 可以放置多个自定义按钮哦  -->
			<template v-slot:btns>
				<view class="gui-padding">
					<button type="default" @tap="comfirm" class="gui-button-mini  gui-bg-blue gui-color-white">
						确认
					</button>
				</view>
			</template>
		</gui-modal>
	</view>
</template>

<script>
	export default {
		name: "hyb-zhuxiao-dialog",
		data() {
			return {
				time: 0,
				code: "",
			};
		},

		props: {
			sms: {
				type: Boolean,
				default: true
			}
		},
		methods: {
			show() {
				uni.showModal({
					title: "注销提醒",
					content: "注销后将消除所信信息，是否确认操作?",
					success: (res) => {
						if (res.confirm) {
							uni.gPost("yuangong/zx/sms").then(() => {
								this.time = 120;
								this.timer();
								this.$refs.popup.open();
							})
							
						}
					}
				})
			},

			timer() {
				if (this.time > 0) {
					this.time--;
					setTimeout(() => {
						this.timer();
					}, 1000)
				}
			},
			comfirm() {
			
				
				if (this.code.length != 4 ) {
					uni.showToast({
						title: "验证错误!",
						icon: 'none'
					})
				} else {
					uni.gPost("yuangong/remove", {
						code: this.code
					}).then(() => {
						this.$refs.popup.close();
							
							uni.redirectTo({
						url: this.$store.state.base.hyzx_luj
					})
					})
				
				uni.gPost("base/info").then((base) => {
					this.$store.commit("set_base", base)
				})
				}
			},
		},

	}
</script>

<style>

</style>